package com.pic.mgt.monitor.parser;

import com.pic.mgt.monitor.WrongUnitFormatException;

public final class businessNameParser extends FormatParser {
	private int bizNameStartFromChar;
	private int bizNameEndToChar;
	
	@Override
	public String parse(Object _confirmationFilename)
							throws WrongUnitFormatException {	
		// 確認是否為 String 型態
		// throws WrongUnitFormatException
		super.checkObjectType(_confirmationFilename, String.class);
		
		String confirmationFilename = (String)_confirmationFilename;
		
		String businessName = null;
		try {
			// throws StringIndexOutOfBoundsException
			businessName = confirmationFilename.
							substring(this.bizNameStartFromChar - 1,
									  this.bizNameEndToChar);
		} catch (IndexOutOfBoundsException e) {			
			throw new WrongUnitFormatException(
					"Confirmation filename '" + confirmationFilename + "' format is invalid.");
		}
		
		return businessName;
	}

	public void setBizNameStartFromChar(int bizNameStartFromChar) {
		this.bizNameStartFromChar = bizNameStartFromChar;
	}

	public void setBizNameEndToChar(int bizNameEndToChar) {
		this.bizNameEndToChar = bizNameEndToChar;
	}

}
